package com.naicheng.ivote.views;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;

import org.json.JSONObject;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources.Theme;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler.Callback;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.wechat.moments.WechatMoments;

import com.naicheng.ivote.R;
import com.naicheng.ivote.adapter.AdapterForLinearLayout;
import com.naicheng.ivote.adapter.CommentChildListAdapter;
import com.naicheng.ivote.adapter.CommentListAdapter;
import com.naicheng.ivote.adapter.HotDetailButsetAdapter;
import com.naicheng.ivote.adapter.ShareOptionAdapter;
import com.naicheng.ivote.adapter.VoteOptionAdapter;
import com.naicheng.ivote.constant.ConstantMine;
import com.naicheng.ivote.doman.BaseResponseEntity;
import com.naicheng.ivote.doman.HotCommentBean;
import com.naicheng.ivote.doman.HotCommentListBean;
import com.naicheng.ivote.doman.HotCommentsChildBean;
import com.naicheng.ivote.doman.HotDetailButsetBean;
import com.naicheng.ivote.doman.HotMainlistItemDetailBean;
import com.naicheng.ivote.doman.HotOptionsBean;
import com.naicheng.ivote.doman.HotShareOptionsBean;
import com.naicheng.ivote.engin.BaseActivity;
import com.naicheng.ivote.engin.ScrollViewListener;
import com.naicheng.ivote.parser.BaseParser;
import com.naicheng.ivote.uiself.AnimDialog;
import com.naicheng.ivote.uiself.CommentLinearLayoutForListView;
import com.naicheng.ivote.uiself.LinearLayoutForListView;
import com.naicheng.ivote.uiself.MyScrollView;
import com.naicheng.ivote.uiself.ShareoptionLinearForListView;
import com.naicheng.ivote.uiself.ToastUtils;
import com.naicheng.ivote.uiself.VoteLinearLayoutForListView;
import com.naicheng.ivote.utils.AppManager;
import com.naicheng.ivote.utils.MyPreferences;
import com.naicheng.ivote.volley.Response.Listener;

public class HotDetailVoteMainActivity extends BaseActivity implements Callback,ScrollViewListener{
	
	
	HotDetailVoteMainActivity CTHMA=HotDetailVoteMainActivity.this;
	private MyPreferences preference;
	AppManager appManager = AppManager.getAppManager();
	private LayoutInflater inflater;
	
	private Handler handler;
	private Handler handlerOption;
	// PopupWindow对象
	private PopupWindow selectPopupWindow = null;
	// 自定义Adapter
	private HotDetailButsetAdapter setAdapter = null;
	private ArrayList<HotDetailButsetBean> setList;
	// 展示所有下拉选项的ListView
	private ListView listView = null;
	
	private HotMainlistItemDetailBean HotDetailBean;
	private String content="";//评论内容
	
	private HashMap<String, String> map;
	
	private ArrayList<HotCommentListBean> conmmentsList;
	private HotCommentBean commentBean;
	private ArrayList<HotCommentsChildBean> conmmentsChildList;
	
	private TextView hot_detail_main_title_tv;
	private TextView hot_detail_main_content_tv;
	private TextView hot_itemdetail_option_tv;
	private TextView hot_itemdetail_sex1_tv;
	private TextView hot_itemdetail_usernames_tv;
	private TextView hot_detail_main_bottom;
	private TextView hot_itemdetail_comments_tv;
	private TextView hot_itemdetail_integral_tv;
	
	private TextView hot_detail_main_back_but;
	private TextView hot_detail_main_set_but;
	private Button hot_itemdetail_praise_but;
	private Button hot_itemdetail_comment_but;
	private Button hot_itemdetail_report_but;
	private Button hot_itemdetail_share_but;
	
	private VoteLinearLayoutForListView hot_detail_main_options_list;
	private CommentLinearLayoutForListView hot_detail_main_comments_list;
	private ShareoptionLinearForListView hot_itemdetail_share_list;
	private MyScrollView hot_detail_main_scrollview;
	
	private VoteOptionAdapter optionsAdapter;
	private CommentListAdapter commentsAdapter;
	private CommentChildListAdapter commentsChildAdapter;
	private ShareOptionAdapter shareOptionAdapter;
	
	private LinearLayout hot_main_title_ll;
	private LinearLayout hot_itemdetail_main_but_all;
	
	private int[] butlocation = new int[2];
	private boolean IsAnim=true;
	private boolean IsAnimUp=true;
	private Animation praiseAnim;
	private Animation commentAnim;
	private Animation reportAnim;
	private Animation shareAnim;
	private Animation praiseAnimFang;
	private Animation commentAnimFang;
	private Animation reportAnimFang;
	private Animation shareAnimFang;
	
	@Override
	protected void setConentView() {
		super.setConentView();
		setContentView(R.layout.activity_hot_main_item_vote);
	}
	@Override
	protected void init() {
		super.init();
		preference=MyPreferences.getPrefer(CTHMA, "myconfig");
		inflater=getLayoutInflater();
		
		setList=new ArrayList<HotDetailButsetBean>();
		HotDetailBean=new HotMainlistItemDetailBean();
		conmmentsList=new ArrayList<HotCommentListBean>();
		commentBean=new HotCommentBean();
		conmmentsChildList=new ArrayList<HotCommentsChildBean>();
		
		handler=new Handler(CTHMA);
		handlerOption=new Handler(CTHMA);
		
		hot_detail_main_back_but=(TextView) findViewById(R.id.hot_detail_main_back_but);
		hot_detail_main_set_but=(TextView) findViewById(R.id.hot_detail_main_set_but);
		hot_detail_main_title_tv=(TextView) findViewById(R.id.hot_detail_main_title_tv);
		hot_detail_main_content_tv=(TextView) findViewById(R.id.hot_detail_main_content_tv);
		hot_itemdetail_option_tv=(TextView) findViewById(R.id.hot_itemdetail_option_tv);
		hot_itemdetail_sex1_tv=(TextView) findViewById(R.id.hot_itemdetail_sex1_tv);
		hot_itemdetail_usernames_tv=(TextView) findViewById(R.id.hot_itemdetail_usernames_tv);
		hot_detail_main_bottom=(TextView) findViewById(R.id.hot_detail_main_bottom);
		hot_itemdetail_comments_tv=(TextView) findViewById(R.id.hot_itemdetail_comments_tv);
		hot_itemdetail_integral_tv=(TextView) findViewById(R.id.hot_itemdetail_integral_tv);
		
		hot_detail_main_back_but=(TextView) findViewById(R.id.hot_detail_main_back_but);
		hot_detail_main_set_but=(TextView) findViewById(R.id.hot_detail_main_set_but);
		hot_itemdetail_praise_but=(Button) findViewById(R.id.hot_itemdetail_praise_but);
		hot_itemdetail_comment_but=(Button) findViewById(R.id.hot_itemdetail_comment_but);
		hot_itemdetail_report_but=(Button) findViewById(R.id.hot_itemdetail_report_but);
		hot_itemdetail_share_but=(Button) findViewById(R.id.hot_itemdetail_share_but);
		
		
		hot_detail_main_options_list=(VoteLinearLayoutForListView) findViewById(R.id.hot_detail_main_options_list);
		hot_detail_main_comments_list=(CommentLinearLayoutForListView) findViewById(R.id.hot_detail_main_comments_list);
		hot_itemdetail_share_list=(ShareoptionLinearForListView) findViewById(R.id.hot_itemdetail_share_list);
		hot_detail_main_scrollview=(MyScrollView) findViewById(R.id.hot_detail_main_scrollview);
		
		hot_main_title_ll=(LinearLayout) findViewById(R.id.hot_main_title_ll);
		hot_itemdetail_main_but_all=(LinearLayout) findViewById(R.id.hot_itemdetail_main_but_all);
		
		
		
		
	}
	@Override
	protected void processLogic() {
		super.processLogic();
		
		//填充set数据
		setButsetData();
		//按钮监听定时器机制
		butAnim();
		
		//检查网络是否连接
		if(ConstantMine.isNetConn){
			getNetDataDetail();
			
		}else{
			ToastUtils.getCenterDownToast(CTHMA, "未发现网络连接，请检查网络！");
		}
		
		
	}
	
	/**
	 * 按钮监听定时器机制
	 */
	public void butAnim(){
		praiseAnim=AnimationUtils.loadAnimation(CTHMA, R.anim.praise_translate_action);
		commentAnim=AnimationUtils.loadAnimation(CTHMA, R.anim.comment_translate_action);
		reportAnim=AnimationUtils.loadAnimation(CTHMA, R.anim.report_translate_action);
		shareAnim=AnimationUtils.loadAnimation(CTHMA, R.anim.share_translate_action);
		praiseAnimFang=AnimationUtils.loadAnimation(CTHMA, R.anim.praise_translate_fang);
		commentAnimFang=AnimationUtils.loadAnimation(CTHMA, R.anim.comment_translate_fang);
		reportAnimFang=AnimationUtils.loadAnimation(CTHMA, R.anim.report_translate_fang);
		shareAnimFang=AnimationUtils.loadAnimation(CTHMA, R.anim.share_translate_fang);
		hot_detail_main_scrollview.setScrollViewListener(CTHMA);
		
		
	}
	
	/**
	 * 监听scrollview滑动事件
	 */
	@Override
	public void onScrollChanged(MyScrollView scrollView, int x, int y,
			int oldx, int oldy) {
		hot_itemdetail_praise_but.getLocationOnScreen(butlocation);
		if(IsAnim){
			if(butlocation[1]>80&butlocation[1]<150){
				if(IsAnimUp){
					butanimShou();
					IsAnimUp=false;
				}else{
					butanimFang();
					IsAnimUp=true;
				}
				IsAnim=false;
			}
		}
		if(butlocation[1]<80||butlocation[1]>150){
			IsAnim=true;
		}
	}
	
	
	
	
	@Override
	protected void setOnClickListener() {
		hot_detail_main_back_but.setOnClickListener(CTHMA);
		hot_detail_main_set_but.setOnClickListener(CTHMA);
		hot_itemdetail_praise_but.setOnClickListener(CTHMA);
		hot_itemdetail_comment_but.setOnClickListener(CTHMA);
		hot_itemdetail_report_but.setOnClickListener(CTHMA);
		hot_itemdetail_share_but.setOnClickListener(CTHMA);
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.hot_detail_main_set_but:
			
			if(null==setList){
				ToastUtils.getCenterDownToast(CTHMA, "暂无数据！");
			}else{
				System.out.println("getWidth:"+hot_detail_main_set_but.getWidth());
				initPopuWindow(hot_detail_main_set_but.getWidth()+80);
				popupWindwShowing(hot_detail_main_set_but);
			}
			
			break;
		case R.id.hot_detail_main_back_but:
			
			appManager.finishActivity();
			
			break;
		case R.id.hot_itemdetail_praise_but:
			if(HotDetailBean.isPraised()){
				itemNetBut("cancelpraise",HotDetailBean.getId(),"");
			}else{
				itemNetBut("praise",HotDetailBean.getId(),"");
			}
			
			break;
		case R.id.hot_itemdetail_comment_but:
			if(HotDetailBean.isAnswered()){
				commentDialog(HotDetailBean.getId());
			}else{
				ToastUtils.getDiyToast(CTHMA, -50, "亲，先投票，后评论");
			}
			
			break;
		case R.id.hot_itemdetail_report_but:
			if(HotDetailBean.isReported()){
				itemNetBut("cancelreport",HotDetailBean.getId(),"");
			}else{
				itemNetBut("report",HotDetailBean.getId(),"");
			}
			
			break;
		case R.id.hot_itemdetail_share_but:
			
			
			break;

		
		}
	}
	
	
	/**
	 * 设置按钮下来列表数据
	 */
	public void setButsetData(){
		HotDetailButsetBean bean;
		
		bean=new HotDetailButsetBean();
		bean.setId(1);
		bean.setText("赞");
		setList.add(bean);
		bean=new HotDetailButsetBean();
		bean.setId(2);
		bean.setText("评论");
		setList.add(bean);
		bean=new HotDetailButsetBean();
		bean.setId(3);
		bean.setText("举报");
		setList.add(bean);
		bean=new HotDetailButsetBean();
		bean.setId(4);
		bean.setText("分享");
		setList.add(bean);
		
		
	}
	
	/**
	 * 获取问题详情基本信息
	 */
	
	public void getNetDataDetail(){
		
//		HotDetailBean=new HotMainlistItemDetailBean();
//		
//		ArrayList<HotOptionsBean> options=new ArrayList<HotOptionsBean>();
//		HotOptionsBean op1=new HotOptionsBean();
//		op1.setOption("A、似的啊的萨芬的困死了免");
//		op1.setOptionid(1);
//		op1.setPercent(3);
//		op1.setVoted(false);
//		HotOptionsBean op2=new HotOptionsBean();
//		op2.setOption("B、似的啊的萨芬的困死了免");
//		op2.setOptionid(2);
//		op2.setPercent(50);
//		op2.setVoted(false);
//		HotOptionsBean op3=new HotOptionsBean();
//		op3.setOption("C、似的啊的萨芬的困死了免");
//		op3.setOptionid(3);
//		op3.setPercent(70);
//		op3.setVoted(true);
//		HotOptionsBean op4=new HotOptionsBean();
//		op4.setOption("D、似的啊的萨芬的困死了免");
//		op4.setOptionid(4);
//		op4.setPercent(90);
//		op4.setVoted(false);
//		HotOptionsBean op5=new HotOptionsBean();
//		op5.setOption("E、似的啊的萨芬的困死了免");
//		op5.setOptionid(5);
//		op5.setPercent(99);
//		op5.setVoted(false);
//		options.add(op1);
//		options.add(op2);
//		options.add(op3);
//		options.add(op4);
//		options.add(op5);
//		
//		ArrayList<HotShareOptionsBean> share=new ArrayList<HotShareOptionsBean>();
//		HotShareOptionsBean sh1=new HotShareOptionsBean();
//		sh1.setOption("A、似的啊的萨芬的困死了免");
//		sh1.setOptionid(1);
//		sh1.setPercent(30);
//		sh1.setCount(40);
//		HotShareOptionsBean sh2=new HotShareOptionsBean();
//		sh2.setOption("B、似的啊的萨芬的困死了免");
//		sh2.setOptionid(2);
//		sh2.setPercent(50);
//		sh2.setCount(40);
//		HotShareOptionsBean sh3=new HotShareOptionsBean();
//		sh3.setOption("C、似的啊的萨芬的困死了免");
//		sh3.setOptionid(3);
//		sh3.setPercent(99);
//		sh3.setCount(40);
//		share.add(sh1);
//		share.add(sh2);
//		share.add(sh3);
//		
//		
//		HotDetailBean.setAccount("测试一");
//		HotDetailBean.setTitle("你说你个二货");
//		HotDetailBean.setContent("送客户的健康思密达看能，否尽快送东门诺卡思" +
//				"密达卡S，D卡肃宁，地税卡客户的健康思密达看能，否尽快送东门诺客户的,健康思密达看能，否尽快送东门诺");
//		HotDetailBean.setAnswered(true);
//		HotDetailBean.setAdditionalid(0);
//		HotDetailBean.setAnswernumber(1);
//		HotDetailBean.setComment(1);
//		HotDetailBean.setCommented(true);
//		HotDetailBean.setId(23);
//		HotDetailBean.setIntegral(1000);
//		HotDetailBean.setIntegral_remain(2000);
//		HotDetailBean.setOptionnumber(4);
//		HotDetailBean.setOptions(options);
//		HotDetailBean.setPraise(1);
//		HotDetailBean.setPraised(false);
//		HotDetailBean.setReported(false);
//		HotDetailBean.setSex("m");
//		HotDetailBean.setShare(share);
//		HotDetailBean.setUserid(1);
//		
//		
//		getNetInit(HotDetailBean);
//		if(null!=HotDetailBean.getOptions()){
//			optionsAdapter=new VoteOptionAdapter(CTHMA, HotDetailBean.getOptions(),handlerOption);
//			hot_detail_main_options_list.setAdapter(optionsAdapter);
//		}
//		if(null!=HotDetailBean.getShare()){
//			shareOptionAdapter=new ShareOptionAdapter(CTHMA, HotDetailBean.getShare(),handlerOption);
//			hot_itemdetail_share_list.setAdapter(shareOptionAdapter);
//		}
		
		map=new HashMap<String, String>();
		map.put("userid", "1");
//		map.put("userid", MyApplication.user.userid);
		map.put("id", ConstantMine.hotItemId+"");
		super.getDataFromServer("questionnaire", map, new Listener<JSONObject>() {
			@Override
			public void onResponse(JSONObject response) {
				BaseResponseEntity<HotMainlistItemDetailBean> mResponse = new BaseParser<HotMainlistItemDetailBean>().parserDomain(response, HotMainlistItemDetailBean.class);
				if (mResponse != null && mResponse.getState()) {
					HotDetailBean=mResponse.getSingleDomain();
					if(null!=HotDetailBean){
						getNetInit(HotDetailBean);
						if(null!=HotDetailBean.getOptions()){
							optionsAdapter=new VoteOptionAdapter(CTHMA, HotDetailBean.getOptions(),handlerOption);
							hot_detail_main_options_list.setAdapter(optionsAdapter);
						}
						if(null!=HotDetailBean.getShare()){
							shareOptionAdapter=new ShareOptionAdapter(CTHMA, HotDetailBean.getShare(),handlerOption);
							hot_itemdetail_share_list.setAdapter(shareOptionAdapter);
						}
						
						getNetCommentlist(HotDetailBean.getId());
					}
				}else{
					ToastUtils.getCenterDownToast(CTHMA, mResponse.getMsg());
				}
			}
			
		}, CTHMA);
		
		
	}
	
	/**
	 * 根据获取的网络数据填充界面信息
	 */
	public void getNetInit(HotMainlistItemDetailBean bean){
		HotMainlistItemDetailBean itembean=bean;
		
		hot_detail_main_title_tv.setText(itembean.getTitle());
		hot_detail_main_content_tv.setText(itembean.getContent());
		hot_itemdetail_option_tv.setText(itembean.getOptionnumber()+"选"+itembean.getAnswernumber());
		hot_itemdetail_usernames_tv.setText(itembean.getAccount());
		
		hot_itemdetail_comments_tv.setText(itembean.getComment()+"条 评论");
		hot_itemdetail_integral_tv.setText("[送积分：共"+itembean.getIntegral()+"剩"+itembean.getIntegral_remain()+"]");
		
		if("f".equals(itembean.getSex())){
			hot_itemdetail_sex1_tv.setText(R.string.list_item_sex2);
			hot_itemdetail_sex1_tv.setTextColor(CTHMA.getResources().getColor(R.color.sex_zi));
		}else{
			hot_itemdetail_sex1_tv.setText(R.string.list_item_sex1);
			hot_itemdetail_sex1_tv.setTextColor(CTHMA.getResources().getColor(R.color.sex_lan));
		}
		hot_itemdetail_praise_but.setText("赞 "+itembean.getPraise());
		if(itembean.isPraised()){
			hot_itemdetail_praise_but.setTextColor(CTHMA.getResources().getColor(R.color.hotdetail_but_lv));
		}else{
			hot_itemdetail_praise_but.setTextColor(CTHMA.getResources().getColor(R.color.bai1));
		}
		hot_itemdetail_comment_but.setText("评论 "+itembean.getComment());
		if(itembean.isCommented()){
			hot_itemdetail_comment_but.setTextColor(CTHMA.getResources().getColor(R.color.hotdetail_but_lv));
		}else{
			hot_itemdetail_comment_but.setTextColor(CTHMA.getResources().getColor(R.color.bai1));
		}
		if(itembean.isReported()){
			hot_itemdetail_report_but.setTextColor(CTHMA.getResources().getColor(R.color.hotdetail_but_lv));
		}else{
			hot_itemdetail_report_but.setTextColor(CTHMA.getResources().getColor(R.color.bai1));
		}
		
		
	}
	
	/**
	 * 获取评论列表
	 */
	
	public void getNetCommentlist(int id){
		
		map=new HashMap<String, String>();
		map.put("id", id+"");
		map.put("page", "1");
		map.put("size", "3");
		super.getDataFromServer("commentlist", map, new Listener<JSONObject>() {
			@Override
			public void onResponse(JSONObject response) {
				BaseResponseEntity<HotCommentBean> mResponse = new BaseParser<HotCommentBean>().parserDomain(response, HotCommentBean.class);
				if (mResponse != null && mResponse.getState()) {
					commentBean=mResponse.getSingleDomain();
					if(null!=commentBean){
						if(null!=commentBean.getComments()){
							conmmentsList=commentBean.getComments();
							commentsAdapter=new CommentListAdapter(CTHMA, conmmentsList);
							hot_detail_main_comments_list.setAdapter(commentsAdapter);
						}
					}
					System.out.println(setList.size());
//					hot_main_title1.setClickable(true);
				}else{
					ToastUtils.getCenterDownToast(CTHMA, mResponse.getMsg());
				}
			}
			
		}, CTHMA);
		
	}
	
	
	/**
	 * 初始化PopupWindow
	 */
	private void initPopuWindow(int mywidth) {
		// PopupWindow浮动下拉框布局
		View mywindow = CTHMA.getLayoutInflater().inflate(R.layout.activity_listselect_main, null);
		listView = (ListView) mywindow.findViewById(R.id.listselect_main_list);
		// 设置自定义Adapter
		setAdapter = new HotDetailButsetAdapter(CTHMA, handler, setList);
		listView.setAdapter(setAdapter);
		selectPopupWindow = new PopupWindow(mywindow, mywidth, android.view.ViewGroup.LayoutParams.WRAP_CONTENT,true);
		selectPopupWindow.setBackgroundDrawable(new BitmapDrawable());
		selectPopupWindow.setOutsideTouchable(true);
	}

	/**
	 * 显示PopupWindow窗口
	 * 
	 * @param popupwindow
	 */
	private void popupWindwShowing(View parent) {
		// 防止下拉框与文本框之间产生缝隙，影响界面美化
		selectPopupWindow.showAsDropDown(parent, 0, -3);
	}

	/**
	 * PopupWindow消失
	 */
	private void dismiss() {
		selectPopupWindow.dismiss();
	}
	
	@Override
	public boolean handleMessage(Message msg) {
		Bundle data = msg.getData();
		int id=data.getInt("selIndex");;
		int idopt=data.getInt("optionid");
		switch (msg.what) {
		case 1:
			if(HotDetailBean.isPraised()){
				itemNetBut("cancelpraise",HotDetailBean.getId(),"");
			}else{
				itemNetBut("praise",HotDetailBean.getId(),"");
			}
			dismiss();
			break;
		case 2:
			if(HotDetailBean.isAnswered()){
				commentDialog(HotDetailBean.getId());
			}else{
				ToastUtils.getDiyToast(CTHMA, -50, "亲，先投票，后评论");
			}
			dismiss();
			break;
		case 3:
			if(HotDetailBean.isReported()){
				itemNetBut("cancelreport",HotDetailBean.getId(),"");
			}else{
				itemNetBut("report",HotDetailBean.getId(),"");
			}
			dismiss();
			break;
		case 4:
			
			dismiss();
			break;
		case 11:
			System.out.println("选项ID："+idopt);
			vote(idopt,HotDetailBean.getId());
			break;
		}
		
		return false;
	}
	
	
	/**
	 * 投票接口
	 */
	public void vote(int optionid,int questionid){
		map=new HashMap<String, String>();
		map.put("userid", "1");
//		map.put("userid", MyApplication.user.userid);
		map.put("questionid", questionid+"");
		map.put("optionid", optionid+"");
		super.getDataFromServer("vote", map, new Listener<JSONObject>() {
			@Override
			public void onResponse(JSONObject response) {
				BaseResponseEntity<String> mResponse = new BaseParser<String>().parserString(response);
				if (mResponse != null && mResponse.getState()) {
					ToastUtils.getCenterDownToast(CTHMA, mResponse.getMsg());
//					startActivity(new Intent(CTHMA,HotDetailMainActivity.class));
				}else{
					ToastUtils.getCenterDownToast(CTHMA, mResponse.getMsg());
				}
			}
			
		}, CTHMA);
	}
	
	/**
	 * 列表item按钮点击接口，赞,评论，举报
	 */
	public void itemNetBut(final String method,int id,String content){
		
		map=new HashMap<String, String>();
		map.put("userid", "1");
//		map.put("userid", MyApplication.user.userid);
		map.put("id", id+"");
		if("comment".equals(method)){
			map.put("content", content);
		}
		
		super.getDataFromServer(method, map, new Listener<JSONObject>() {
			@Override
			public void onResponse(JSONObject response) {
				BaseResponseEntity<String> mResponse = new BaseParser<String>().parserString(response);
				if (mResponse != null && mResponse.getState()) {
					ToastUtils.getCenterDownToast(CTHMA, mResponse.getMsg());
					if("praise".equals(method)){
						hot_itemdetail_praise_but.setText("赞"+(HotDetailBean.getPraise()+1));
						hot_itemdetail_praise_but.setTextColor(CTHMA.getResources().getColor(R.color.hotdetail_but_lv));
					}else if("cancelpraise".equals(method)){
						hot_itemdetail_praise_but.setText("赞"+(HotDetailBean.getPraise()-1));
						hot_itemdetail_praise_but.setTextColor(CTHMA.getResources().getColor(R.color.bai1));
					}else if("report".equals(method)){
						hot_itemdetail_report_but.setTextColor(CTHMA.getResources().getColor(R.color.hotdetail_but_lv));
					}else if("cancelreport".equals(method)){
						hot_itemdetail_report_but.setTextColor(CTHMA.getResources().getColor(R.color.bai1));
					}
				}else{
					ToastUtils.getCenterDownToast(CTHMA, mResponse.getMsg());
				}
			}
			
		}, CTHMA);
		
	}
	
	/**
	 * 列表item按钮点击，评论对话框
	 */
	public void commentDialog(final int id){
		
		View view=inflater.inflate(R.layout.comment_dialog, null);
		final Dialog dialog=new Dialog(CTHMA, R.style.dialog);
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
		dialog.addContentView(view, params);
		final EditText comment_dialog_content=(EditText) view.findViewById(R.id.comment_dialog_content);
		final TextView comment_dialog_num=(TextView) view.findViewById(R.id.comment_dialog_num);
		Button comment_dialog_but=(Button) view.findViewById(R.id.comment_dialog_but);
		comment_dialog_num.setText(""+99);
		
		comment_dialog_content.addTextChangedListener(new TextWatcher() {
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				content=comment_dialog_content.getText().toString();
				if(99<=content.length()){
					s=s.subSequence(0, 99);
					content=content.subSequence(0, 99).toString();
				}
				
				comment_dialog_num.setText(""+(99-content.length()));
			}
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}
			@Override
			public void afterTextChanged(Editable s) {
				content=comment_dialog_content.getText().toString();
				if(99<=content.length()){
					content=content.subSequence(0, 99).toString();
				}
				comment_dialog_num.setText(""+(99-content.length()));
			}
		});
		
		comment_dialog_but.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				itemNetBut("comment",id,content);
				InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);  
				imm.hideSoftInputFromWindow(comment_dialog_content.getWindowToken(), 0); 
				dialog.dismiss();
			}
		});
		
		Window window = dialog.getWindow();
		window.setGravity(Gravity.BOTTOM);
		WindowManager.LayoutParams lp = window.getAttributes();
		window.setAttributes(lp);
		dialog.show();
	}
	
	
	/**
	 * 收缩动画界面
	 */
	public void butanimShou(){
		
		View view=inflater.inflate(R.layout.but_anim_shou, null);
		final Dialog dialog=new Dialog(CTHMA, R.style.dialog);
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
		params.width=LayoutParams.MATCH_PARENT;
		dialog.addContentView(view, params);
		
		Button but_anim_praise_but=(Button) view.findViewById(R.id.but_anim_praise_but);
		Button but_anim_comment_but=(Button) view.findViewById(R.id.but_anim_comment_but);
		Button but_anim_report_but=(Button) view.findViewById(R.id.but_anim_report_but);
		Button but_anim_share_but=(Button) view.findViewById(R.id.but_anim_share_but);
		TextView but_anim_back_but=(TextView) view.findViewById(R.id.but_anim_back_but);
		TextView but_anim_set_but=(TextView) view.findViewById(R.id.but_anim_set_but);
		
		but_anim_praise_but.startAnimation(praiseAnim);
		but_anim_comment_but.startAnimation(commentAnim);
		but_anim_report_but.startAnimation(reportAnim);
		but_anim_share_but.startAnimation(shareAnim);
		but_anim_praise_but.setVisibility(View.INVISIBLE);
		but_anim_comment_but.setVisibility(View.INVISIBLE);
		but_anim_report_but.setVisibility(View.INVISIBLE);
		but_anim_share_but.setVisibility(View.INVISIBLE);
		
		
		Window window = dialog.getWindow();
		window.setGravity(Gravity.TOP);
		WindowManager.LayoutParams lp = window.getAttributes();
		window.setAttributes(lp);
		dialog.show();
		new Thread(){
			@Override
			public void run() {
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
					dialog.dismiss();
				}
				dialog.dismiss();
			}
			
		}.start();
		
	}
	
	/**
	 * 放出动画界面
	 */
	public void butanimFang(){
		
		View view=inflater.inflate(R.layout.but_anim_shou, null);
		final Dialog dialog=new Dialog(CTHMA, R.style.dialog);
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
		params.width=LayoutParams.MATCH_PARENT;
		dialog.addContentView(view, params);
		
		Button but_anim_praise_but=(Button) view.findViewById(R.id.but_anim_praise_but);
		Button but_anim_comment_but=(Button) view.findViewById(R.id.but_anim_comment_but);
		Button but_anim_report_but=(Button) view.findViewById(R.id.but_anim_report_but);
		Button but_anim_share_but=(Button) view.findViewById(R.id.but_anim_share_but);
		TextView but_anim_back_but=(TextView) view.findViewById(R.id.but_anim_back_but);
		TextView but_anim_set_but=(TextView) view.findViewById(R.id.but_anim_set_but);
		
		but_anim_praise_but.setVisibility(View.INVISIBLE);
		but_anim_comment_but.setVisibility(View.INVISIBLE);
		but_anim_report_but.setVisibility(View.INVISIBLE);
		but_anim_share_but.setVisibility(View.INVISIBLE);
		but_anim_praise_but.startAnimation(praiseAnimFang);
		but_anim_comment_but.startAnimation(commentAnimFang);
		but_anim_report_but.startAnimation(reportAnimFang);
		but_anim_share_but.startAnimation(shareAnimFang);
		
		
		Window window = dialog.getWindow();
		window.setGravity(Gravity.TOP);
		WindowManager.LayoutParams lp = window.getAttributes();
		window.setAttributes(lp);
		dialog.show();
		new Thread(){
			@Override
			public void run() {
				try {
					Thread.sleep(1300);
				} catch (InterruptedException e) {
					e.printStackTrace();
					dialog.dismiss();
				}
				dialog.dismiss();
			}
			
		}.start();
		
	}
	
	/**
	 * 微信朋友圈
	 */
	public void shareWeinin(){
		Platform sinaweibo = ShareSDK.getPlatform(this,
				WechatMoments.NAME);
		sinaweibo.setPlatformActionListener(shareListener);
		WechatMoments.ShareParams sinaSp = new WechatMoments.ShareParams();
		sinaSp.shareType = Platform.SHARE_WEBPAGE;
		// 四个参数不能少也不能错
		sinaSp.title = "";
		sinaSp.text = "";
		// 网页的链接
//		sinaSp.url = url;
//		// 图片的网络地址
//		sinaSp.imageData = drawableToBitmap();
		// sinaSp.imageUrl = imageUrl;
		sinaweibo.share(sinaSp);
	}
	
	
	PlatformActionListener shareListener = new PlatformActionListener() {
		@Override
		public void onError(Platform arg0, int arg1, Throwable arg2) {
//			Toast("分享失败" + "arg2");
		}

		@Override
		public void onComplete(Platform arg0, int arg1,
				HashMap<String, Object> arg2) {
//			Toast("分享成功");
		}

		@Override
		public void onCancel(Platform arg0, int arg1) {
//			Toast("分享取消");
		}
	};

	

}
